//
//  SEHospitalizeOrderListCell.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/16.
//

import UIKit

protocol SEHospitalizeOrderListCellDelegate: NSObjectProtocol {
    func hospitalizeOrderListCell(_ cell: SEHospitalizeOrderListCell, didClickedDetailWith viewModel: SEHospitalizeOrderDetailViewModel)
    func hospitalizeOrderListCell(_ cell: SEHospitalizeOrderListCell, didClickedPayWith viewModel: SEHospitalizeOrderDetailViewModel)
    func hospitalizeOrderListCell(_ cell: SEHospitalizeOrderListCell, didClickedCancelWith viewModel: SEHospitalizeOrderDetailViewModel)
}

class SEHospitalizeOrderListCell: UITableViewCell {

    static let className = "SEHospitalizeOrderListCell"
    static let reuseId = className


    @IBOutlet weak var stackBgView: UIView! {
        didSet{
            stackBgView.layer.cornerRadius = 4
            stackBgView.layer.borderWidth = 1
            stackBgView.layer.borderColor = Asset.main.color.withAlphaComponent(0.15).cgColor
            stackBgView.layer.masksToBounds = true
        }
    }

    @IBOutlet weak var detailBtn: UIButton! {
        didSet {
            detailBtn.layer.cornerRadius = detailBtn.frame.size.height / 2.0
            detailBtn.layer.borderWidth = 1
            detailBtn.layer.borderColor = Asset.main.color.cgColor
            detailBtn.layer.masksToBounds = true
        }
    }

    @IBOutlet weak var payBtn: UIButton! {
        didSet {
            payBtn.layer.cornerRadius = payBtn.frame.size.height / 2.0
            payBtn.layer.borderWidth = 1
            payBtn.layer.borderColor = Asset.main.color.cgColor
            payBtn.layer.masksToBounds = true
        }
    }

    @IBOutlet weak var cancelBtn: UIButton! {
        didSet {
            cancelBtn.layer.cornerRadius = cancelBtn.frame.size.height / 2.0
            cancelBtn.layer.borderWidth = 1
            cancelBtn.layer.borderColor = Asset.textGrayLightest.color.cgColor
            cancelBtn.layer.masksToBounds = true
        }
    }

    @IBAction func detailBtnAction(_ sender: UIButton) {
        delegate?.hospitalizeOrderListCell(self, didClickedDetailWith: viewModel)
    }
    @IBAction func payBtnAction(_ sender: UIButton) {
        delegate?.hospitalizeOrderListCell(self, didClickedPayWith: viewModel)
    }
    @IBAction func cancelBtnAction(_ sender: UIButton) {
        delegate?.hospitalizeOrderListCell(self, didClickedCancelWith: viewModel)
    }

    @IBOutlet weak var doctorNameLabel: UILabel!
    @IBOutlet weak var jobTitleLabel: UILabel!
    @IBOutlet weak var statusLabel: UILabel!
    @IBOutlet weak var hospitalNameLabel: UILabel!
    @IBOutlet weak var departmentLabel: UILabel!
    @IBOutlet weak var describeLabel: UILabel!
    @IBOutlet weak var patientNameLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!

    weak var delegate: SEHospitalizeOrderListCellDelegate?
    var viewModel = SEHospitalizeOrderDetailViewModel()

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    func updateCell(viewModel: SEHospitalizeOrderDetailViewModel) {
        self.viewModel = viewModel
        doctorNameLabel.text = viewModel.model.doctorName
        patientNameLabel.text = viewModel.patientNameDescribe
        describeLabel.text = viewModel.model.illness
        timeLabel.text = viewModel.model.createTime
        jobTitleLabel.text = viewModel.model.jobTitle
        departmentLabel.text = viewModel.model.deptName
        hospitalNameLabel.text = viewModel.model.hospitalName ?? " "
        statusLabel.text = viewModel.model.status.title
        statusLabel.textColor = viewModel.model.status.titleColor
        payBtn.isHidden = viewModel.isHiddenPay
        detailBtn.isHidden = viewModel.isHiddenDetail
        cancelBtn.isHidden = viewModel.isHiddenCancel
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
